angular.module('starter.controllers')
.controller('ActivitylistCtrl', function($scope, museumFac, $stateParams, $timeout, $location, cfg, $cookies, uploadImg, $ionicScrollDelegate) {
	$scope.width1 = $(window).width();
  	$scope.width2 = ($scope.width1-24)/16*9;
    $scope.header_chosen = $stateParams.type;

	$scope.turn = function(flag){
		$scope.header_chosen = flag;
        $scope.getProduct();
	}

	$scope.change_language = function(id){
	    $scope.language = id;
	    var expireDate = new Date();  
		expireDate.setDate(expireDate.getDate() + 30);                
		$cookies.put('language', id, {'expires': expireDate.toUTCString()});
		location.reload();
		if(id == 0){
			document.getElementById('title').innerHTML = '提示';
			document.getElementById('windowclosebutton').value = '确定';
		}else{
			document.getElementById('title').innerHTML = 'Hint';
			document.getElementById('windowclosebutton').value = 'Confirm';
		}

	}

	$scope.getLanguage = function(){
    	$scope.language = $cookies.get('language');
    	if($scope.language){
      		$scope.language = $scope.language;
    	}else{
      		$scope.language = 0;
    	}
    	if($scope.language == 0){
			document.getElementById('title').innerHTML = '提示';
			document.getElementById('windowclosebutton').value = '确定';
		}else{
			document.getElementById('title').innerHTML = 'Hint';
			document.getElementById('windowclosebutton').value = 'Confirm';
		}
  	}
  	$scope.getLanguage();

	$scope.checkOpenid = function(){
        $scope.url = window.location.href;
        wx.ready(function(){
          wx.onMenuShareTimeline({
            title: $scope.share_name + ' | 活动列表\r\n四方当代美术馆', // 分享标题
            link: $scope.url, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
            imgUrl: 'http://store.sifangartmuseum.org.cn/Public/museum/www/img/logo.png', // 分享图标
            success: function () { 
                // 用户确认分享后执行的回调函数
            },
            cancel: function () { 
                // 用户取消分享后执行的回调函数
            }
        });
        // 获取“分享给朋友”按钮点击状态及自定义分享内容接口
        wx.onMenuShareAppMessage({
            title: $scope.share_name + ' | 活动列表',  // 分享标题
            desc: '四方当代美术馆', // 分享描述
            link: $scope.url, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
            imgUrl: 'http://store.sifangartmuseum.org.cn/Public/museum/www/img/logo.png', // 分享图标
            type: '', // 分享类型,music、video或link，不填默认为link
            dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
            success: function () { 
                // 用户确认分享后执行的回调函数
            },
            cancel: function () { 
                // 用户取消分享后执行的回调函数
            }
          });
        });
	}


    // 获取商品信息
    $scope.getProduct = function(){
        museumFac.info.exhibitions({
            type:$scope.header_chosen
        },function(data){
            $scope.products = data.info;
            angular.forEach($scope.categorys, function(item){            
                if(item.id == $scope.header_chosen){
                    $scope.share_name = item.name;
                }
            });
            $scope.checkOpenid();
        },function(data){
            alert(data.data.info);
        });
    }
    $scope.getProduct();

    $scope.gotoDetail = function(id){
        // $location.url('ticket_detail/' + id);
        window.location.href = cfg.baseUrl + 'home/index/exhibition?exhibitionId=' + id;
    }
  
})